package com.cn.kehong.controller;

import com.cn.kehong.api.ISysItemService;
import com.cn.kehong.domain.SysDevice;
import com.cn.kehong.domain.SysItem;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @类名:SysItemController
 * @包名:com.cn.kehong.controller
 * @作者:chenxingliang
 * @时间:2022-11-23 17:24
 * @版本:1.0.0
 */

@Controller
@RequestMapping("/sysItem")
public class SysItemController {

    @Autowired
    private ISysItemService sysItemService;


    @ResponseBody
    @RequestMapping("/getMgItemList/{frontToken}")
    public JsonResponse<List<SysItem>> getMgItemList(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemList(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getMgItemSelect/{frontToken}")
    public JsonResponse<List<SysItem>> getMgItemSelect(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemSelect(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getAllMgItemList/{frontToken}")
    public JsonResponse<List<SysItem>> getAllMgItemList(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getAllMgItemList();
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getMgItemDefaultValue/{frontToken}")
    public JsonResponse<String> getMgItemDefaultValue(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.getMgItemDefaultValue(mgItem);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/addMgItemDetail/{frontToken}")
    public JsonResponse<String> addMgItemDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addMgItemDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateMgItemDetail/{frontToken}")
    public JsonResponse<String> updateMgItemDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    //区域位置
    @ResponseBody
    @RequestMapping("/addWorkshopDetail/{frontToken}")
    public JsonResponse<String> addWorkshopDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addWorkshopDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    //区域位置
    @ResponseBody
    @RequestMapping("/updateWorkshopDetail/{frontToken}")
    public JsonResponse<String> updateWorkshopDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateWorkshopDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateMgItemValue/{frontToken}")
    public JsonResponse<String> updateMgItemValue(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemValue(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deleteMgItemDetail/{frontToken}")
    public JsonResponse<String> deleteMgItemDetail(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.deleteMgItemDetail(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/api/getMgItemSelectByType")
    public JsonResponse<List<SysItem>> getMgItemSelectByType(String type) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemSelectByType(type);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }


    /**
     * @author : Huiyan feng
     * @date   : 2023/12/6
     * @param  : [frontToken]
     * @return : com.cn.kehong.utils.JsonResponse<java.util.Map<java.lang.String,java.util.List<com.cn.kehong.domain.SysItem>>>
     * @description : getCategoryMap 基础数据--物料下拉框联动
     */
    @ResponseBody
    @RequestMapping("/getCategoryMap/{frontToken}")
    public JsonResponse<Map<String,List<SysItem>>> getCategoryMap(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,List<SysItem>>> response = new JsonResponse<>();
        Map<String,List<SysItem>> result = sysItemService.getCategoryMap();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/2/2
     * @param  : [mgItem, frontToken]
     * @return : com.cn.kehong.utils.JsonResponse<java.lang.String>
     * @description : 挤塑机号
     */
    @ResponseBody
    @RequestMapping("/updateMgItemCodeDetail/{frontToken}")
    public JsonResponse<String> updateMgItemCodeDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemCodeDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/addMgItemCodeDetail/{frontToken}")
    public JsonResponse<String> addMgItemCodeDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addMgItemCodeDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    //厂房下拉框
    @ResponseBody
    @RequestMapping("/getDeviceList/{frontToken}")
    public JsonResponse<List<SysItem>> getDeviceList(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> deviceList = sysItemService.getDeviceList();
        response.setResult(deviceList);
        response.setSuccess(true);
        return response;
    }

    //通过厂房查询车间
    @RequestMapping("/getDeviceWorkshopList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysItem>> getDeviceWorkshopList(@RequestBody String factory,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> deviceWorkshopList = sysItemService.getDeviceWorkshopList(factory);
        response.setResult(deviceWorkshopList);
        response.setSuccess(true);
        return response;
    }

    //基础数据--厂房框联动
    @ResponseBody
    @RequestMapping("/getWorkshopMap/{frontToken}")
    public JsonResponse<Map<String,List<SysItem>>> getWorkshopMap(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,List<SysItem>>> response = new JsonResponse<>();
        Map<String,List<SysItem>> result = sysItemService.getWorkshopMap();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }



    //通过厂房车间查询对应基准节拍之和
    @RequestMapping("/getReferenceByWorkshop/{frontToken}")
    @ResponseBody
    public JsonResponse<String> getReferenceByWorkshop(String workshop) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.getReferenceByWorkshop(workshop);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

//    //通过厂房车间线体查询对应基准节拍
//    @RequestMapping("/getReferenceByWorkshopLine/{frontToken}")
//    @ResponseBody
//    public JsonResponse<String> getReferenceByWorkshopLine(String workshop,String lineBody) throws Exception {
//        JsonResponse<String> response = new JsonResponse<String>();
//        String result = sysItemService.getReferenceByWorkshopLine(workshop,lineBody);
//        response.setResult(result);
//        response.setSuccess(true);
//        return response;
//    }

    //通过厂房车间查询对应基准节拍
    @RequestMapping("/getReferenceByWorkshopBasic/{frontToken}")
    @ResponseBody
    public JsonResponse<String> getReferenceByWorkshopBasic(String workshop,String type) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.getReferenceByWorkshopBasic(workshop,type);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }


    //基准节拍新增
    @ResponseBody
    @RequestMapping("/addMgItemBasicDetail/{frontToken}")
    public JsonResponse<String> addMgItemBasicDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addMgItemBasicDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }


    // 基准节拍修改
    @ResponseBody
    @RequestMapping("/updateMgItemBasicDetail/{frontToken}")
    public JsonResponse<String> updateMgItemBasicDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemBasicDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }



    //原辅料新增
    @RequestMapping("/addRawMaterial/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addRawMaterial(@RequestBody List<SysItem> sysItems,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = sysItemService.addRawMaterial(sysItems);
        return CommonUtil.getResponseData(response,result);
    }


    //修改
    @RequestMapping("/updateRawMaterial/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateRawMaterial(@RequestBody SysItem sysItem, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = sysItemService.updateRawMaterial(sysItem);
        return CommonUtil.getResponseData(response,result);
    }


    //产品目录新增
    @ResponseBody
    @RequestMapping("/addProduct/{frontToken}")
    public JsonResponse<String> addProduct(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addProduct(mgItem);
        return CommonUtil.getResponseData(response,result);
    }


    //产品目录修改
    @RequestMapping("/updateProduct/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateProduct(SysItem sysItem, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = sysItemService.updateProduct(sysItem);
        return CommonUtil.getResponseData(response,result);
    }


    //获取原辅料管理中的物料编码
    @RequestMapping("/getMaterialCode/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysItem>> getMaterialCode(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<SysItem>> response = new JsonResponse<>();
        List<SysItem> sysItems = sysItemService.getMaterialCode();
        response.setResult(sysItems);
        response.setSuccess(true);
        return response;
    }

    //获取产品规格中的规格
    @RequestMapping("/getMaterialTitle/{frontToken}")
    @ResponseBody
    public JsonResponse<List<SysItem>> getMaterialTitle(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<SysItem>> response = new JsonResponse<>();
        List<SysItem> sysItems = sysItemService.getMaterialTitle();
        response.setResult(sysItems);
        response.setSuccess(true);
        return response;
    }

    //用于班次查询厂房，只需要厂房不需要车间 去重
    @ResponseBody
    @RequestMapping("/getMgItemListFactoryName/{frontToken}")
    public JsonResponse<List<SysItem>> getMgItemListFactoryName(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemListFactoryName(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }
}

